subroutine print_exit_msg(lunit,cunit,w,t,d,s,l,t_array0,myrank)
  use param
  implicit none

  integer,intent(in) :: lunit,cunit,w,myrank
  real(dbl),intent(in) :: t,d,s,l
  integer,intent(in) :: t_array0(8)

  character(len=8) :: d_time_str
  character(len=len_linebuf) :: tstr
  
  integer :: i

  call print_d_time(t_array0,d_time_str)

  if (myrank.eq.0) then
     do i=1,w
        tstr(i:i)='-'
     end do

     ! Print the run parameters to the terminal
     print '(a)',tstr(1:w)
     print '(1x,"Simulation time=",1pe11.5,1x,"(s)")',t
     print '(1x,"Elapsed DPA in PKA=",1pe11.5)',d
     print '(1x,"Elapsed DPA in PKA+SKA=",1pe11.5)',s
     print '(1x,"Number of loops=",i0)',int(l)
     print '(1x,"Lap time=",1x,a)',d_time_str
     print '(a)',tstr(1:w)
  end if
  
  ! Write it to the log file
  write(lunit,'(a)') tstr(1:w)
  write(lunit,'(1x,"Simulation time=",1pe11.5,1x,"(s)")') t
  write(lunit,'(1x,"Elapsed DPA in PKA=",1pe11.5)') d
  write(lunit,'(1x,"Elapsed DPA in PKA+SKA=",1pe11.5)') s
  write(lunit,'(1x,"Number of loops=",i0)') int(l)
  write(lunit,'(1x,"Lap time=",1x,a)') d_time_str
  write(lunit,'(a)') tstr(1:w)

#ifdef DEBUG
  ! Write the running time to the debugging file
  call log_msg1(cunit,"")
  call log_msg1(cunit,"Lap time")
  call log_msg1(cunit,d_time_str)
#endif

  return

end subroutine print_exit_msg
